package com.huihui.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.huihui.R;
import com.huihui.utils.LoadImageUtil;
import com.huihui.widget.ResizableImageView;

import java.util.List;

/**
 * Created by Administrator on 2018/9/8.
 */
public class MyPagerAdapter extends PagerAdapter {

    private Context mContext;
    private List<String> mList;
    public MyPagerAdapter(Context context, List<String> list){
        mContext = context;
        mList = list;
    }
    @Override
    public int getCount() {

        return mList == null ? 0:mList.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view==object;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }
    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.preview,null);
        ResizableImageView imageView = view.findViewById(R.id.previvewid);
        LoadImageUtil.displayImagePreview(mContext,mList.get(position),imageView,R.color.color_e9e9e9,false);
//        Glide.with(mContext).load(mList.get(position)).placeholder(R.mipmap.logo).error(R.mipmap.logo).into(imageView);
        container.addView(view);
        return view;
    }
}
